package red.lightblue.admin.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Flux;
import red.lightblue.admin.base.BaseResponse;
import red.lightblue.admin.dto.TypeDTO;
import red.lightblue.admin.service.TypeService;
import red.lightblue.admin.vo.TypeVO;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 这里把productType , 和product相关的都合并到了一起
 */
@RestController
public class ProductController extends AbstractBaseController {

    @Autowired
    private TypeService typeService;


    @GetMapping("/product/showAllProductType")
    public Flux<TypeVO> showAllProductType(){
        List<TypeDTO> typeDTOS = typeService.getAllProductType();
        Stream<TypeVO> productTypeVos = typeDTOS.stream().map(type->
        {TypeVO vo = new TypeVO();vo.setId(type.getId()).setName(type.getTypeName()).setpId(type.getParentTypeId());
            return  vo;});
        return Flux.fromStream(productTypeVos);
    }

    @GetMapping("/product/getChildrenProductType")
    public BaseResponse getChildrenProductType(@RequestParam Integer id){

        return null;
    }
}
